﻿using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RTW.OA.Areas.System.Servers
{
    public class RoleServers
    {
        private readonly IRepository<role> RoleRepository;
        private readonly IRepository<department> DeptRepository;
        private readonly IRepository<sys_menu> Sys_MenuRepository;
        private readonly IRepository<actionpermission> ActionRepository;
        public RoleServers()
        {
            RoleRepository = new DapperRepository<role>();
            DeptRepository=new DapperRepository<department>();
            Sys_MenuRepository = new DapperRepository<sys_menu>();
            ActionRepository=new DapperRepository<actionpermission>();
        }

        public List<role> GetRoles()
        {
            return RoleRepository.GetAllEnumerable().ToList();
        }

        public role GetRoleById(string id)
        {
            return RoleRepository.GetById(id);
        }

        public List<department> GetDepts()
        {
            return DeptRepository.GetAllEnumerable().ToList();
        }

        public List<sys_menu> GetMenus()
        {
            return Sys_MenuRepository.GetAllEnumerable().ToList();
        }

        internal List<actionpermission> GetMenuActions(int menu_id)
        {
            return ActionRepository.SqlWithParams("select * from actionpermission where MENU_ID=@MENU_ID",new { MENU_ID = menu_id }).ToList();
        }


        internal void Add(role model)
        {
            RoleRepository.Insert(model);
        }

        internal void Update(role model)
        {
            RoleRepository.Update(model);
        }
    }
}